FROM node:18-alpine as builder

WORKDIR /app

# 1. 复制 package 文件
COPY frontend/package*.json ./

# 2. 安装依赖（使用缓存和国内镜像）
RUN npm config set registry https://mirrors.huaweicloud.com/repository/npm && \
    npm config set fetch-retry-maxtimeout 60000 && \
    npm config set fetch-retry-mintimeout 10000 && \
    npm install --no-optional --prefer-offline

# 3. 复制源代码
COPY frontend/ .

# 4. 构建（显示详细日志）
RUN npm run build --verbose

# 生产阶段
FROM nginx:alpine

# 复制构建结果
COPY --from=builder /app/dist /usr/share/nginx/html

# 复制 nginx 配置
COPY docker/frontend/nginx.conf /etc/nginx/conf.d/default.conf

# 暴露端口（与 nginx 配置一致）
EXPOSE 3000